package com.chehejia.devmng.platform.base.constant;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 枚举转换操作
 *
 * @author shanfeilong
 */
public class EnumHelper {

    public static <E extends Enum<E>> Map<String, EnumEntry> getEnumMap(final Class<E> enumClass, BaseEnum[] baseEnums) {
        final Map<String, EnumEntry> map = new LinkedHashMap<>();
        int i = 0;
        for (final E e : enumClass.getEnumConstants()) {
            EnumEntry entry = new EnumEntry(baseEnums[i].getCode(), baseEnums[i].getMessage());
            map.put(e.name(), entry);
            i++;
        }
        return map;
    }

    private static class EnumEntry {

        private Object value;

        private Object text;

        public EnumEntry(Object value, Object text) {
            this.value = value;
            this.text = text;
        }

        public Object getValue() {
            return value;
        }

        public void setValue(Object value) {
            this.value = value;
        }

        public Object getText() {
            return text;
        }

        public void setText(Object text) {
            this.text = text;
        }
    }
}
